<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <father></father>
    </div>

    <template id="father">
        <div class="father">
            <p>这是父组件</p>
            <p>这是儿子跟他说的话 {{parentMsg}} </p>
            <hr>
            <son :tell-dad="change"></son>
        </div>
    </template>

    <template id="son">
        <div class="son">
            <p>这是子组件===》{{msg}}</p>
            <p><button @click="tellDad(msg)">告诉爸爸</button></p>
        </div>
    </template>
    

</body>
<script src="./base/vue.js"></script>

<script>

    // 父组件可以将自己方法传递给子组件来调用，
    //实现子组件更改父组件的数据

    Vue.component("father",{
        template:"#father",
        data(){
            return {
                parentMsg:""
            }
        },
        methods:{
            change(msg){
                this.parentMsg = msg;
            }
        }
    })
    Vue.component("son",{
        template:"#son",
        props:["tellDad"],
        data(){
            return {
                msg:"今晚不学习了。。"
            }
        }
    })

    new Vue({
        el:"#app"
    })
    
</script>
</html>